//
//  tab_Info.m
//  VivaModa
//
//  Created by Owly MacBook on 01.02.13.
//  Copyright (c) 2013 private_busines. All rights reserved.
//

#import "tab_Info.h"
#import "info_cell.h"

@interface tab_Info ()

@end

@implementation tab_Info
@synthesize famous_gr;
@synthesize scrollView;
@synthesize delivery_view;
@synthesize contacts;
@synthesize activation_card;
@synthesize stock;
@synthesize tableView;
@synthesize activationCard;

@synthesize jay_lane;
@synthesize kennet;

NSDictionary *dict_image;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
    
    [self.kennet setFont:[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:34]];
    [self.jay_lane setFont:[UIFont fontWithName:@"American Retro" size:31.0]];
    
    
    [self setNaviganionImg];
    [self setNavigationTitle];
    
    self.view.backgroundColor = [Singleton sharedMySingleton].backgroundTableView;
    
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        CGSize result = [[UIScreen mainScreen] bounds].size;
        if(result.height == 480)
        {
            // iPhone Classic
            [scrollView setContentSize:CGSizeMake(320, 740)];
        }
        if(result.height == 568)
        {
            // iPhone 5
            [scrollView setContentSize:CGSizeMake(320, 660)];
        }
    }
    
    dict_image = [NSDictionary dictionaryWithObjects:@[@"stock_icon",@"plan",@"support_icon",@"contacts",@"stars_icon",@"avtivation_icon"] forKeys:@[@"stock",@"deliver",@"support",@"contacts",@"famous",@"activation"]];
    
}




#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 1;
    }else{
        return 5;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"info_cell_identifi";
    
    
    
    info_cell *cell = nil;
    cell = (info_cell *) [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if(!cell)
    {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"info_cell" owner:nil options:nil];
        for(id currentObject in topLevelObjects)
        {
            if([currentObject isKindOfClass:[info_cell class]])
            {
                cell = (info_cell *)currentObject;
                break;
            }
        }
    }
    
    if (indexPath.section==0) {
        cell.title_name.text = @"Знаменитости";
        cell.image.image = [UIImage imageNamed:[dict_image objectForKey:@"famous"]];
    }else{
        switch (indexPath.row) {
            case 0:{
                cell.title_name.text = @"Доставка";
                //cell.image.image= [UIImage imageNamed:[dict_image objectForKey:@"deliver"]];
                break;}
            case 1:{
                cell.title_name.text = @"Акции, скидки, бонусы";
                //cell.image.image= [UIImage imageNamed:[dict_image objectForKey:@"stock"]];
                
                break;}
            case 2:{
                cell.title_name.text = @"Активация клубных карт";
                //cell.image.image= [UIImage imageNamed:[dict_image objectForKey:@"activation"]];
                break;}
            case 3:{
                cell.arrow.hidden = YES;
                cell.title_name.text = @"Обратная связь";
                //cell.image.image= [UIImage imageNamed:[dict_image objectForKey:@"support"]];
                break;}
            case 4:{
                cell.title_name.text = @"Контакты";
                //cell.image.image= [UIImage imageNamed:[dict_image objectForKey:@"contacts"]];
                break;}
            default:
                break;
        }
    }
    
    [cell.title_name setFont:[UIFont fontWithName:@"Century Gothic" size:17.0]];
    [cell.title_name setTextColor:[UIColor colorWithRed:242.0/255.0 green:240.0/255.0 blue:234.0/255.0 alpha:1]];
    
    [cell.title_name setHighlightedTextColor:[UIColor purpleColor]];
    
    
    UIView *selectedView = [[UIView alloc] init];
    selectedView.backgroundColor = [UIColor clearColor];
    cell.selectedBackgroundView = selectedView;
    
    return cell;
}


- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section==0) {
        [self swichFamous_group:self];
    }else{
        switch (indexPath.row) {
            case 0:{
                [self swithDeliveryView:self];
                break;}
            case 1:{
                [self swithStockView:self];
                break;}
            case 2:{
                [self swithActivationCardView:self];
                break;}
            case 3:{
                [self writeToSupport:self];
                break;}
            case 4:{
                [self swithContactsView:self];
                break;}
            default:
                break;
        }

    }
}








- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(IBAction)swichFamous_group:(id)sender{
    if (!famous_gr) {
        famous_gr = [[famous_groups alloc] initWithNibName:@"famous_groups" bundle:nil];
    }
    [self.navigationController pushViewController:famous_gr animated:YES];
}

-(IBAction)swithDeliveryView:(id)sender{
    if (!delivery_view) {
        delivery_view = [[delivery alloc] initWithNibName:@"delivery" bundle:nil];
    }
    [self.navigationController pushViewController:delivery_view animated:YES];
}

-(IBAction)swithStockView:(id)sender{
    if (!stock) {
        stock = [[Stock_View alloc] initWithNibName:@"Stock_View" bundle:nil];
    }
    [self.navigationController pushViewController:stock animated:YES];
}

-(IBAction)swithActivationCardView:(id)sender{
    /*if (!activation_card) {
        activation_card = [[ActivationCardView alloc] initWithNibName:@"ActivationCardView" bundle:nil];
    }
    [self.navigationController pushViewController:activation_card animated:YES];*/
    
    if (!activationCard) {
        activationCard = [[ActivationCard alloc] initWithNibName:@"ActivationCard" bundle:nil];
    }
    [self.navigationController pushViewController:activationCard animated:YES];
    
    
    
}

-(IBAction)swithContactsView:(id)sender{
    if (!contacts) {
        contacts = [[Contact_View alloc] initWithNibName:@"Contact_View" bundle:nil];
    }
    [self.navigationController pushViewController:contacts animated:YES];
}

- (void)mailComposeController:(MFMailComposeViewController*)controller
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError*)error;
{
    [self dismissModalViewControllerAnimated:YES];
}

-(IBAction)writeToSupport:(id)sender {
    if ([MFMailComposeViewController canSendMail]) {
        MFMailComposeViewController* mailController = [[MFMailComposeViewController alloc] init];
        [mailController.navigationBar setBarStyle:UIBarStyleBlack];
        mailController.mailComposeDelegate = self;
        [mailController setToRecipients:[NSArray arrayWithObjects:@"office@viva-viva.ru",nil]];
        [mailController setSubject:@"Свяжитесь с нами"];
        //[[[[mailController viewControllers] lastObject] navigationItem] setTitle:@"Свяжитесь с нами"];
        
        [mailController setMessageBody:[NSString stringWithFormat:@"Здравствуйте, \n\n\n\nОтправлено из приложения для iOS\n"]  isHTML:NO];
        

        [self presentModalViewController:mailController animated:YES];
        //[[[[mailController viewControllers] lastObject] navigationItem] setTitle:@"Свяжитесь с нами"];
            }
    else {
        NSLog(@"%@", @"Sorry, you need to setup mail first!");
    }
}


-(void)setNaviganionImg{
    if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
        UIImage *image = [UIImage imageNamed:@"navigation_bg"];
        [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
        
    }
}

-(void)setNavigationTitle{
    UILabel *lblTitle = [[UILabel alloc] init];
    lblTitle.text = @"Инфо";
    lblTitle.backgroundColor = [UIColor clearColor];
    lblTitle.textColor = [UIColor colorWithRed:242.0/255.0 green:240.0/255.0 blue:234.0/255.0 alpha:1];
    
    lblTitle.font = [UIFont fontWithName:@"American Retro" size:27.0];
    [lblTitle sizeToFit];
    
    self.navigationItem.titleView = lblTitle;
}

@end
